﻿Namespace Seguranca

    Public Class Authentication

        Shared Function IsAutenticado() As Boolean
            Return (New Page).User.Identity.IsAuthenticated
        End Function

        ''' <summary>
        ''' userData = Role
        ''' </summary>
        ''' <param name="Name"></param>
        ''' <param name="userData">Role's</param>
        ''' <remarks></remarks>
        Public Shared Sub _FormsAuthentication(ByVal Name As String, ByVal userData As String)
            FormsAuthentication.Initialize()
            Dim fat As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, Name, DateTime.Now, DateTime.Now.AddMinutes(30), False, userData, FormsAuthentication.FormsCookiePath)
            System.Web.HttpContext.Current.Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)))
        End Sub

        Public Shared Sub Logout(Optional ByVal RedirecionaLogin As Boolean = False)
            System.Web.HttpContext.Current.Session.Clear()
            FormsAuthentication.SignOut()
            FormsAuthentication.RedirectToLoginPage()
        End Sub

    End Class

End Namespace